@echo off

chcp 65001
REM STM32标准库模板项目
REM by jackie lee @ 2021.10.16
REM such as: lib-src-copy.bat D:\Document\temp\stm32\en.stsw-stm32054_v3.5.0\STM32F10x_StdPeriph_Lib_V3.5.0 D:\Document\LeeSp\Stm32Pro\Template\StdTemplate
REM 源包类似：en.stsw-stm32054_v3.5.0  chcp修改编码为utf-8
REM 源包目录 %1 目标项目路径 %2

SET "LIB_DIR=%~1"
SET "TARGET_DIR=%~2"

REM 判断是否参数合法
if not defined LIB_DIR goto nosource
if not exist %LIB_DIR% goto nosource
if not defined TARGET_DIR goto noproject
if not exist %TARGET_DIR% goto noproject

SET TARGET=%TARGET_DIR%\Startup
SET TARGET_DRIVER=%TARGET_DIR%\Libraries
SET TARGET_USER=%TARGET_DIR%\User

if not exist %LIB_DIR% goto failure

REM check target
if not exist %TARGET% mkdir %TARGET%
if not exist %TARGET_DRIVER% mkdir %TARGET_DRIVER%
if not exist %TARGET_DRIVER%\inc mkdir %TARGET_DRIVER%\inc
if not exist %TARGET_DRIVER%\src mkdir %TARGET_DRIVER%\src
if not exist %TARGET_USER% mkdir %TARGET_USER%

COPY /Y %LIB_DIR%\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\* %TARGET%
COPY /Y %LIB_DIR%\Libraries\CMSIS\CM3\CoreSupport\* %TARGET%
COPY /Y %LIB_DIR%\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\stm32f10x.h %TARGET%
COPY /Y %LIB_DIR%\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.h %TARGET%
COPY /Y %LIB_DIR%\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.c %TARGET%

REM config
COPY /Y %LIB_DIR%\Project\STM32F10x_StdPeriph_Template\stm32f10x_conf.h %TARGET_USER%
COPY /Y %LIB_DIR%\Project\STM32F10x_StdPeriph_Template\stm32f10x_it.c %TARGET_USER%
COPY /Y %LIB_DIR%\Project\STM32F10x_StdPeriph_Template\stm32f10x_it.h %TARGET_USER%
COPY /Y %LIB_DIR%\Project\STM32F10x_StdPeriph_Template\main.c %TARGET_USER%

REM TYPE null > %TARGET_USER%\system_stm32f1xx.h
REM COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Src\system_stm32f1xx.c %TARGET_USER%

REM driver files
XCOPY /Y /S %LIB_DIR%\Libraries\STM32F10x_StdPeriph_Driver\inc %TARGET_DRIVER%\inc
XCOPY /Y /S %LIB_DIR%\Libraries\STM32F10x_StdPeriph_Driver\src %TARGET_DRIVER%\src

goto end

:nosource
echo input the en.stsw-stm32054_v3.xx folder for param 1
goto end

:noproject
echo input the smt32 project folder for param 2
goto end

:failure
echo %LIB_DIR% not exists


:end

exit

